import service from "../utils/request";

/**
 * 获取招式列表
 * @param {Object} params 查询参数
 * @param {string} params.query - 搜索关键词
 * @returns {Promise} 招式列表数据
 */
export function getMovesList(params = {}) {
    return service.get("/moves", { params });
}

/**
 * 获取所有技能（按编号排序）
 * @returns {Promise} 所有技能列表数据
 */
export function getAllMoves() {
    return service.get("/moves/all");
}

/**
 * 根据宝可梦名称查询技能
 * @param {string} pokemonName 宝可梦名称
 * @param {Object} params 可选参数
 * @param {string} params.learnMethod 学习方式 (level/tm)
 * @param {number} params.minLevel 最小等级
 * @param {number} params.maxLevel 最大等级
 * @returns {Promise} 技能列表数据
 */
export function getMovesByPokemon(pokemonName, params = {}) {
    return service.get("/moves/pokemon", {
        params: {
            pokemonName,
            ...params
        }
    });
}

/**
 * 根据宝可梦ID查询技能
 * @param {number} pokemonId 宝可梦ID
 * @param {Object} params 可选参数
 * @param {string} params.learnMethod 学习方式 (level/tm)
 * @param {number} params.minLevel 最小等级
 * @param {number} params.maxLevel 最大等级
 * @returns {Promise} 技能列表数据
 */
export function getMovesByPokemonId(pokemonId, params = {}) {
    return service.get("/moves/pokemon-id", {
        params: {
            pokemonId,
            ...params
        }
    });
}

/**
 * 根据属性名称查询技能
 * @param {string} typeName 属性名称
 * @returns {Promise} 技能列表数据
 */
export function getMovesByType(typeName) {
    return service.get("/moves/type", { params: { typeName } });
}

/**
 * 根据技能名称搜索技能
 * @param {string} moveName 技能名称
 * @returns {Promise} 搜索结果
 */
export function getMovesByName(moveName) {
    return service.get("/moves/search", { params: { moveName } });
}

/**
 * 根据等级区间查询技能
 * @param {number} minLevel 最小等级
 * @param {number} maxLevel 最大等级
 * @param {string} learnMethod 学习方式 (可选)
 * @returns {Promise} 技能列表数据
 */
export function getMovesByLevel(minLevel, maxLevel, learnMethod) {
    const params = { minLevel, maxLevel };
    if (learnMethod) {
        params.learnMethod = learnMethod;
    }
    return service.get("/moves/level", { params });
}

/**
 * 综合查询技能接口
 * @param {Object} queryVO 查询参数对象
 * @returns {Promise} 技能列表数据
 */
export function queryMoves(queryVO) {
    return service.post("/moves/query", queryVO);
}

/**
 * 搜索招式
 * @param {string} query 搜索关键词
 * @returns {Promise} 搜索结果
 */
export function searchMoves(query) {
    return service.get("/moves", { params: { query } });
}

/**
 * 获取模拟招式数据（用于后端API不可用时的备用方案）
 * @returns {Promise} 模拟招式列表数据
 */
export function getMockMovesList() {
    // 当后端不可用时的备用数据
    return Promise.resolve({
        flag: true,
        data: [
            {
                id: 1,
                moveName: "十万伏特",
                typeId: 5,
                typeName: "电",
                typeColor: "#F8D030",
                category: "special",
                power: 90,
                accuracy: 100,
                pp: 15,
                description: "用强力的电击攻击对手。有时会让对手陷入麻痹状态。"
            },
            {
                id: 2,
                moveName: "火花",
                typeId: 2,
                typeName: "火",
                typeColor: "#F08030",
                category: "special",
                power: 40,
                accuracy: 100,
                pp: 25,
                description: "向对手喷射小火焰进行攻击。有时会让对手陷入灼伤状态。"
            },
            {
                id: 3,
                moveName: "水枪",
                typeId: 3,
                typeName: "水",
                typeColor: "#6890F0",
                category: "special",
                power: 40,
                accuracy: 100,
                pp: 25,
                description: "向对手猛烈地喷射水流进行攻击。"
            },
            {
                id: 4,
                moveName: "撞击",
                typeId: 1,
                typeName: "一般",
                typeColor: "#A8A878",
                category: "physical",
                power: 40,
                accuracy: 100,
                pp: 35,
                description: "用整个身体撞向对手进行攻击。"
            },
            {
                id: 5,
                moveName: "叶片刀",
                typeId: 4,
                typeName: "草",
                typeColor: "#78C850",
                category: "physical",
                power: 55,
                accuracy: 95,
                pp: 25,
                description: "用叶片切斩对手进行攻击。容易击中要害。"
            },
            {
                id: 6,
                moveName: "地震",
                typeId: 9,
                typeName: "地面",
                typeColor: "#E0C068",
                category: "physical",
                power: 100,
                accuracy: 100,
                pp: 10,
                description: "利用地震的冲击攻击自己周围所有的宝可梦。"
            },
            {
                id: 7,
                moveName: "冰冻光束",
                typeId: 6,
                typeName: "冰",
                typeColor: "#98D8D8",
                category: "special",
                power: 90,
                accuracy: 100,
                pp: 10,
                description: "向对手发射冰冷的光束进行攻击。有时会让对手陷入冰冻状态。"
            },
            {
                id: 8,
                moveName: "精神强念",
                typeId: 11,
                typeName: "超能力",
                typeColor: "#F85888",
                category: "special",
                power: 90,
                accuracy: 100,
                pp: 10,
                description: "向对手发送强念波进行攻击。有时会让对手混乱。"
            },
            {
                id: 9,
                moveName: "岩石滑坡",
                typeId: 13,
                typeName: "岩石",
                typeColor: "#B8A038",
                category: "physical",
                power: 75,
                accuracy: 90,
                pp: 10,
                description: "向对手投掷大岩石进行攻击。有时会让对手畏缩。"
            },
            {
                id: 10,
                moveName: "影子球",
                typeId: 14,
                typeName: "幽灵",
                typeColor: "#705898",
                category: "special",
                power: 80,
                accuracy: 100,
                pp: 15,
                description: "投掷一团黑影进行攻击。有时会降低对手的特防。"
            },
            {
                id: 11,
                moveName: "龙息",
                typeId: 16,
                typeName: "龙",
                typeColor: "#7038F8",
                category: "special",
                power: 60,
                accuracy: 100,
                pp: 20,
                description: "将强烈的气息吹向对手进行攻击。有时会让对手麻痹。"
            },
            {
                id: 12,
                moveName: "钢翼",
                typeId: 17,
                typeName: "钢",
                typeColor: "#B8B8D0",
                category: "physical",
                power: 70,
                accuracy: 90,
                pp: 25,
                description: "用坚硬的翅膀敲打对手进行攻击。有时会提高自己的攻击。"
            }
        ],
        msg: "模拟招式数据加载成功"
    });
} 